<template>
	<view class="wrap"
		style="height: 400px;background: url(../../../static/aidex/images/8cdf8eebc4589f07d7d3d638d34eeae.png) no-repeat left top;background-size: 100% auto;">
		<view class="logo">智慧水务</view>
		<div v-if="loginType === 'currentPhone'">
			<!-- <u-tabs :list="list" :is-scroll="false" :current="current" @change="onClickItem"></u-tabs> -->
			<view v-if="current === 0" class="content">
				<view class="list">
					<view class="list-call">
						<view class="iconfont icon-avatar" style="font-size: 18px;color:#5473e8;">
							&nbsp;&nbsp;&nbsp;&nbsp;账号</view>
						<input class="u-input" type="text" style="padding-top:3px;font-size: 17px;align-content: center"
							v-model="username" maxlength="32" :placeholder="$t('login.placeholderAccount')"
							value="admin" />
					</view>
					<view class="list-call">
						<view class="iconfont icon-key" style="font-size: 18px;color:#5473e8;align-content: center">
							&nbsp;&nbsp;&nbsp;&nbsp;密码</view>
						<input class="u-input" type="text" style="padding-top:3px;font-size: 17px;" v-model="password"
							maxlength="32" :placeholder="$t('login.placeholderPassword')" :password="!showPassword"
							value="admin123" />
						<image class="u-icon-right"
							:src="'/static/aidex/login/eye_' + (showPassword ? 'open' : 'close') + '.png'"
							@click="showPass()"></image>
					</view>
				</view>
				<view class="button" @click="submit('1')"><text>登录</text></view>
				<!-- <view class="login-bottom-box">
				<u-divider> 更多登录方式 </u-divider>
				<view class="oauth2">
					<u-icon class="u-icon" size="100" color="#36c956" name="weixin-circle-fill" @click="wxLogin"></u-icon>
					<u-icon class="u-icon" size="100" color="#23a0f0" name="qq-circle-fill" @click="qqLogin"></u-icon>
				</view>
				<view class="copyright">
					登录即代表您已阅读并同意<u-link href="#">用户协议</u-link> 与 <u-link href="#">隐私政策</u-link>
				</view>
			</view> -->
			</view>
			<!-- 	<view v-if="current === 1">
				<view class="list">
					<view class="list-call">
						<view class="iconfont icon-shouji" style="font-size: 22px;color:#5473e8;"></view>
						<u-field v-model="phoneNo" label="+86" placeholder="请填写手机号" style="width: 100%;"
							:border-bottom="false">
						</u-field>
					</view>
					<div style="padding:25rpx 0 0;">
						还没有账号？<navigator class="reg-link" url="reg" open-type="navigate">{{$t('login.reg')}}</navigator>
					</div>
				</view>
				<view class="button" @click="nextStep()"><text>下一步</text></view>
				<view class="login-bottom-box">
					<u-divider> 更多登录方式 </u-divider>
					<view class="oauth2">
						<u-icon class="u-icon" size="100" color="#36c956" name="weixin-circle-fill"
							@click="wxLogin"></u-icon>
						<u-icon class="u-icon" size="100" color="#23a0f0" name="qq-circle-fill"
							@click="qqLogin"></u-icon>
					</view>
					<view class="copyright">
						登录即代表您已阅读并同意<u-link href="#">用户协议</u-link> 与 <u-link href="#">隐私政策</u-link>
					</view>
				</view>
			</view> -->
		</div>

		<!-- <div v-if="loginType !== 'currentPhone'">
			<view class="currentPhone-box">
				<view class="number-text">183****1005</view>
				<view class="other-text">认证服务由中国移动提供。</view>
				<u-button type="primary" @click="submit('3')">本机号码一键登录</u-button>
				<u-button @click="qiehuanLogin()">其他登录方式</u-button>
			</view>
			<view class="login-bottom-box">
				<view class="copyright">
					登录即代表您已阅读并同意<u-link href="#">用户协议</u-link> 与 <u-link href="#">隐私政策</u-link>
				</view>
			</view>
		</div> -->

	</view>
</template>
<script>
	import base64 from '@/common/base64.js';
	import JSEncrypt from '@/node_modules/jsencrypt/bin/jsencrypt.js'
	export default {
		data() {
			return {
				phoneNo: '',
				username: '',
				password: '',
				loginType: 'currentPhone',
				showPassword: false,
				remember: true,
				isValidCodeLogin: false,
				validCode: '',
				current: 0,
				activeColor: '#007aff',
			};
		},
		onLoad() {
			// this.$u.api.index({
			// 	loginCheck: true
			// }).then(res => {
			// 	if (res.code == '200') {
			// 		uni.reLaunch({
			// 			url: '/pages/sys/msg/index'
			// 		});
			// 	}
			// });
		},
		methods: {
			showPass() {
				this.showPassword = !this.showPassword;
			},
			qiehuanLogin() {
				this.loginType = 'other'
			},
			onClickItem(index) {
				this.current = index;
			},
			refreshImgValidCode(e) {
				if (this.vuex_token == '') {
					this.$u.api.index().then(res => {
						this.imgValidCodeSrc = this.vuex_config.baseUrl + '/validCode?__sid=' +
							res.sessionid + '&t=' + new Date().getTime();
					});
				} else {
					this.imgValidCodeSrc = this.vuex_config.baseUrl + '/validCode?__sid=' +
						this.vuex_token + '&t=' + new Date().getTime();
				}
				this.validCode = '';
			},
			submit(loginType) {
				if (this.username.length == 0) {
					this.$u.toast('请输入账号');
					return;
				}
				if (this.password.length == 0) {
					this.$u.toast('请输入密码');
					return;
				}
				this.$u.api.loginRsa().then(res => {
					let publicKey = res;
					let rsaEncrypt = new JSEncrypt();
					rsaEncrypt.setPublicKey(publicKey);
					let password = rsaEncrypt.encrypt(this.password)

					this.$u.api.login({
							userName: this.username,
							passWord: password,
						})
						.then(res => {
							if (res.code == '0') {
								// 	// 获取当前登录用户信息
								this.$u.api.userInfo({
										"algorithmProcessId": "getUserName",
										"param": {
											"data": {
												"userName": this.username
											}
										}
									})
									.then(result => {
										try {
											uni.setStorageSync("username", this.username);
											uni.reLaunch({
												url: '/pages/sys/index/navigavtion'
											});

										} catch (e) {
											console.log(e, 'sessionstorge')
										}
										try {
											uni.setStorageSync("uuid", result.data.data.result[0]
												.user_uuid);
										} catch (e) {
											console.log(e, 'sessionstorge')
										}
									});
							} else {
								this.$u.toast("用户名或密码错误，请重新登录！");
							}

						});
				})

			},
			wxLogin(res) {
				this.$u.toast('微信登录');
			},
			qqLogin() {
				this.$u.toast('QQ 登录');
			},
			logins(tokenValue) {
				// let realPass = document.getElementById('passWordreal')
				// //('#passWordreal').val();
				// let encodePass = Base64.encode(realPass)
				// encodePass = Base64.encode(encodePass)
				// encodePass = Base64.encode(encodePass)
				// encodePass = Base64.encode(encodePass)
				// encodePass = Base64.encode(encodePass)
				// //$('input[name=passWord]').val(encodePass);
				// document.querySelector('input[name=passWord]').val(encodePass);

				// $.ajax({
				// 	url: 'login',
				// 	data: 'userName=' + $('#userName').val() + '&passWord=' + encodePass,
				// 	type: 'post',
				// 	complete: function(x, data) {
				// 		var token = x.getResponseHeader('token'); //获取token
				// 		if (token != '' || token == null || token == 'null') {
				// 			sessionStorage.setItem("token", token);
				// 			location.href = 'getPtFormHtml?code=h5_general_catalogue'
				// 		} else {
				// 			sessionStorage.removeItem("token")
				// 			location.href = 'login-error'
				// 		}
				// 	}
				// })
				var token = tokenValue //获取token
				if (token != '' || token == null || token == 'null') {
					uni.setStorage("token", token);
					//location.href = 'getPtFormHtml?code=h5_general_catalogue'
				} else {
					uni.setStorage("token")
					//location.href = 'login-error'
				}
			}

		}
	};
</script>
<style lang="scss">
	@import '/style/index.scss';

</style>